package com.bwsoft.portal.action;

import java.util.List;

import org.apache.log4j.Logger;

import com.bwsoft.admin.domain.Advertisement;
import com.bwsoft.admin.domain.News;
import com.bwsoft.admin.domain.NewsCategory;
import com.bwsoft.admin.domain.valueObject.NewsVO;

public class NewsAction extends PortalBaseAction {

	private static Logger LOG = Logger.getLogger(NewsAction.class);

	private String s_category;

	private int pagecount = 0;
	private int pageSize = 0;
	private List<NewsCategory> newsCategoryList;
	private Advertisement adLeft;
	private Advertisement adMid;
	private Advertisement adRight;
	
	public String list() {
		Integer category = null;
		if (s_category != null)
			category = Integer.valueOf(s_category);
		//通过编号查询字典集合的大小	
		long recordcount = newsService.getCount(category);
		pagecount = (int)(recordcount % getRows() == 0 ? (recordcount / getRows()) : (recordcount / getRows() + 1));
		
		if (pagecount < 1)
		{
			pageSize = 1;
			pagecount = 1;
		}
		else if (pagecount > 8)
			pageSize = 8;
		else
			pageSize = pagecount;
		
		newsCategoryList = newsCategoryService.findAll();
		
		//获取广告
		adLeft = adService.getAdByPos(11);
		adMid = adService.getAdByPos(12);
		adRight = adService.getAdByPos(13);
		
		return "list";
	}
	
	public String getNewsJson() {
		
		List<News> newsList=null;
		List<NewsVO> newsVOs;
			
		//通过字典编号查询字典详情的分页集合
		newsList = newsService.findData(page, rows, s_category,  "", "", "");
		
		newsVOs = newsService.getVo(newsList);
		
		responseJson.put("rows", newsVOs);

		return "mapJsonResult";
	}
	
	public String contentShow(){
		news=newsService.newsModifyInfo(news.getNewsId());
		newsCategoryList = newsCategoryService.findAll();
		
		//获取广告
		adLeft = adService.getAdByPos(11);
		adMid = adService.getAdByPos(12);
		adRight = adService.getAdByPos(13);
		
		return "contentShow";
	}

	public String getS_category() {
		return s_category;
	}

	public void setS_category(String s_category) {
		this.s_category = s_category;
	}
	
	public int getPagecount() {
		return pagecount;
	}

	public void setPagecount(int pagecount) {
		this.pagecount = pagecount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pagecountshow) {
		this.pageSize = pagecountshow;
	}
	
	public List<NewsCategory> getNewsCategoryList() {
		return newsCategoryList;
	}

	public void setNewsCategoryList(List<NewsCategory> newsCategoryList) {
		this.newsCategoryList = newsCategoryList;
	}

	public Advertisement getAdLeft() {
		return adLeft;
	}

	public void setAdLeft(Advertisement adLeft) {
		this.adLeft = adLeft;
	}

	public Advertisement getAdMid() {
		return adMid;
	}

	public void setAdMid(Advertisement adMid) {
		this.adMid = adMid;
	}

	public Advertisement getAdRight() {
		return adRight;
	}

	public void setAdRight(Advertisement adRight) {
		this.adRight = adRight;
	}
}
